package com.ssy.lingxi.common.constant.order;

import com.ssy.lingxi.common.language.LanguageHolder;

import java.util.Arrays;

/**
 * 订单类型枚举
 * @author 万宁
 * @version 2.0.0
 * @date 2021-07-15
 */
public enum OrderTypeEnum {

    /**
     * 询价采购 -  1
     */
    INQUIRY_TO_PURCHASE(1, "询价采购"),

    /**
     * 需求采购 - 2
     */
    NEED_TO_PURCHASE(2, "需求采购"),

    /**
     * 现货采购 - 3
     */
    SPOT_PURCHASING(3, "现货采购"),

    /**
     * 集采 - 4
     */
    COLLECTIVE_PURCHASE(4, "集采"),

    /**
     * 渠道直采 - 5
     */
    CHANNEL_STRAIGHT_MINING(5, "渠道直采"),

    /**
     * 渠道现货 - 6
     */
    CHANNEL_SPOT(6, "渠道现货"),

    /**
     * 积分兑换 - 7
     */
    CREDITS_EXCHANGE(7, "积分兑换"),

    /**
     * 渠道积分兑换 - 8
     */
    CHANNEL_POINT_EXCHANGE(8, "渠道积分兑换"),

    /**
     * 采购询价合同 - 9
     */
    QUERY_PRICE_CONTRACT(9, "采购询价合同"),

    /**
     * 采购竞价合同 - 10
     */
    PRICE_COMPETITION_CONTRACT_PURCHASE(10, "采购竞价合同"),

    /**
     * 采购招标合同 - 11
     */
    PURCHASE_CONTRACT_BIDDING(11, "采购招标合同"),

    /**
     * 请购单采购 - 12
     */
    REQUISITION_TO_PURCHASE(12, "请购单采购"),

    /**
     * 跨境电商进口 - 13
     */
    COMMERCE_IMPORT(13, "跨境电商进口");

    OrderTypeEnum(Integer code, String name) {
        this.code = code;
    }

    /**
     * 订单类型枚举值
     */
    private Integer code;

    public Integer getCode() {
        return code;
    }

    public String getName() {
        return LanguageHolder.getName(this.getClass(), this.getCode());
    }

    /**
     * 根据类型枚举值获取名称
     * @param code 类型枚举值
     * @return 类型名称
     */
    public static String getNameByCode(Integer code) {
        return LanguageHolder.getName(OrderTypeEnum.class, code);
    }

    /**
     * 根据类型枚举值获取枚举
     * @param code 类型枚举值
     * @return 枚举
     */
    public static OrderTypeEnum parse(Integer code) {
        return Arrays.stream(OrderTypeEnum.values()).filter(e -> e.getCode().equals(code)).findFirst().orElse(null);
    }
}
